package org.jeecg.modules.business.outbound.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.basic.warehouse.entity.WmsBasicWarehouseArea;
import org.jeecg.modules.basic.warehouse.service.IWmsBasicWarehouseAreaService;
import org.jeecg.modules.business.outbound.entity.vo.*;
import org.jeecg.modules.business.outbound.service.IWmsOutReceiptTaskLightService;
import org.jeecg.modules.business.repertory.service.IWmsTaskMaterialLightService;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 出库任务-亮灯
 *
 * @author gongwenkai
 * @version 1.0.0
 * @since 2023-10-10
 */
@RequiredArgsConstructor
@Api(tags = "出库任务-亮灯")
@RestController
@RequestMapping("/business/wmsOutReceiptTask/light")
@Slf4j
public class WmsOutReceiptTaskLightController {

    private final IWmsTaskMaterialLightService wmsTaskMaterialLightService;

    private final IWmsBasicWarehouseAreaService wmsBasicWarehouseAreaService;

    private final IWmsOutReceiptTaskLightService wmsOutReceiptTaskLightService;

    /**
     * 查询仓库下的库区信息
     * @param wmsBasicWarehouseId
     * @return
     */
    @ApiOperation(value = "查询仓库下的库区信息", notes = "查询仓库下的库区信息")
    @GetMapping(value = "/listWarehouseArea")
    public Result<List<WmsBasicWarehouseArea>> listWarehouseArea(@RequestParam(value="wmsBasicWarehouseId") String wmsBasicWarehouseId){
        List<WmsBasicWarehouseArea> list=wmsBasicWarehouseAreaService.list(new LambdaQueryWrapper<WmsBasicWarehouseArea>()
                .eq(WmsBasicWarehouseArea::getWmsBasicWarehouseId,wmsBasicWarehouseId)
        );
        return Result.ok(list);
    }

    /**
     * 按条件打开所有灯
     * @return
     */
    @ApiOperation(value = "按条件打开所有灯", notes = "按条件打开所有灯")
    @PostMapping(value = "/openAllLight")
    public Result<List<String>> openAllLight( @RequestBody OpenLightFilterVO openLightFilterVO){

        List<String> successIdList=wmsOutReceiptTaskLightService.openAllLight(openLightFilterVO);
        return Result.ok(successIdList);
    }

    /**
     * 按条件关闭所有灯
     * @param closeLightFilterVO
     * @return
     */
    @ApiOperation(value = "按条件打开所有灯", notes = "按条件打开所有灯")
    @PostMapping(value = "/closeAllLight")
    public Result<List<String>> closeAllLight(@Valid @RequestBody CloseLightFilterVO closeLightFilterVO){

        List<String> successIdList=wmsOutReceiptTaskLightService.closeAllLight(closeLightFilterVO);
        return Result.ok(successIdList);
    }

    /**
     * 扫码关闭一个灯
     * @param closeOneLightVO
     * @return
     */
    @ApiOperation(value = "扫码关闭一个灯", notes = "扫码关闭一个灯")
    @PostMapping(value = "/closeOneLight")
    public Result<Void> closeOneLight(@Valid @RequestBody CloseOneLightVO closeOneLightVO){
        String errorMessage=wmsOutReceiptTaskLightService.closeOneLight(closeOneLightVO);
        if(StrUtil.isEmpty(errorMessage)){
            return Result.OK();
        }else{
            return Result.OK(errorMessage);
        }
    }

    /**
     * 获取灯状态
     * @return
     */
    @ApiOperation(value = "获取灯状态", notes = "获取灯状态")
    @GetMapping(value = "/getLightStatus")
    public Result<String> getLightStatus(@RequestParam("taskMaterialId")String taskMaterialId){
        String lightStatus=wmsOutReceiptTaskLightService.getLightStatus(taskMaterialId);
        return Result.OK(lightStatus);
    }

}
